<template>
	<view class="login-con">
		
		<view class="content">
			
			<form >
					<!-- <view class="uni-form-item uni-column">
						<view class="input-con">
							<input class="uni-input" focus name="userName"   placeholder="请输入账号" />
						</view>
					</view>
				  <view class="uni-form-item uni-column">
						<view class="input-con c-flex c-flex-row c-item-center">
							<input class="uni-input" :password="isHidePwd" name="password"  placeholder="请输入密码" />
							<image v-if="isHidePwd" class="eye-close" src="../../static/images/login/login-icon-eye.png" @click="isHidePwd = false;"></image>
							<image v-if="!isHidePwd" class="eye-open" src="../../static/images/login/login-icon-eye-open.png" @click="isHidePwd = true;"></image>
						</view>
				  </view> -->
					<button class="submit-bt" form-type="submit"  @tap="thirdLogin" v-if="isShowBt">登录</button>
					<view class="submit-bt_1  c-flex jc-center c-item-center" @tap="senderLogin">
						<image :src="loginCommon+'delivery_icon.png'"></image>
						<view>配送员登录</view>
					</view>
				</form>				
			</view>
			<image class="login_img_1" :src="loginCommon+'login.png'"></image>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data(){
			return {
				isHidePwd:true,
				isShowBt:false,
				loginCommon:this.$API.IMG_URL+'/liquefied-mall/common/'
			}
		},
		onLoad() {
			uni.setNavigationBarColor({
				backgroundColor:'#f9ead5',
				frontColor:'#000000'
			});
			this.isShowBt = uni.getStorageSync('login_user_delivery')
		},
		methods:{
			...mapMutations(['setRole']),
			thirdLogin(){
				uni.navigateTo({
					url:'./third_login'
				})
			},
			senderLogin(){
				uni.navigateTo({
					url:'/pages/login/delivery_login'
				})
			},
			formSubmit(e){
				const name = e.detail.value.userName;
				const pwd = e.detail.value.password;
				if(name == '' ||  pwd == ''){
					return;
				}
				uni.showLoading({title:'加载中...'});
				this.$API.login({'username': name,'password': pwd,appCode:'energy'}).then(res =>{
					uni.hideLoading();
					// 记录token
					wx.setStorageSync('token', res.token);
					wx.setStorageSync('tenants', JSON.stringify(res.tenants));
					if(res.hasOwnProperty('tenants') && res.tenants.length>0){
					  wx.setStorageSync('tenantId', res.tenants[0].id)
					}
					let tenantType =  res.tenants[0].appType;
					if(tenantType ==4){
						this.setRole('user');
						
						uni.setStorageSync('type', 'user')
						 
						uni.switchTab({
							url:'../plat-menu/index'
						})
					}else if(tenantType ==3){
						this.setRole('gas');
						
						 uni.setStorageSync('type', 'delivery')
						uni.switchTab({
							url:'../plat-menu/index'
						})
					}

					
					//uni.setStorageSync("firing",'1')
					// uni.navigateTo({
					// 	url:'../plat-menu/index?type=0'
					// })
					
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-con{
		
		.title{text-align: center;color: #FFFFFF;margin-bottom: 114rpx;}
		.login_img_1{width: 750rpx;height:980rpx;position: absolute;top: 0; right:0;z-index: -2;}
		.logo{width: 126rpx;height: 80rpx;margin-left: 64rpx;margin-top: 318rpx;}
		.content{
			padding: 950rpx 62rpx 0 62rpx;
			
			.txt1{
				margin-top: 46rpx;
			}
			.txt2{
				margin-top: 16rpx;
			}
			.txt{
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #333333;
			}
			.input-con{
				position: relative;
				height: 98rpx;margin-top: 56rpx;background: #F7F8FA;border-radius: 16rpx;padding: 0 40rpx;
				input{height: 98rpx;flex:1;}
				.eye-close,.eye-open{width: 44rpx;height: 44rpx;right: 40rpx;top: 28rpx;}
			}
			.submit-bt{
				
				width: 608rpx;
				height: 92rpx;
				line-height: 92rpx;
				background: linear-gradient( 180deg, #F18858 0%, #E86547 100%);
				border-radius: 46rpx;
				
				
				font-size: 30rpx;font-weight: bold;color: #FFFFFF;margin-top: 86rpx;border: 1rpx solid #FFFFFF;
			}
			.submit-bt_1{
				text-align: center;
				    
				    padding-top: 280rpx;
				image{
					width: 58rpx;
					height: 58rpx;
				}
				view{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #8B959F;
					padding-left: 15rpx;
				}
				
			}
		}
	}
</style>
